import path from 'node:path'
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import Components from 'unplugin-vue-components/vite'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
import { PlusResolver } from './plugin/auto-import-resolver'

const rootDir = path.resolve(__dirname, '..')
const packages = path.resolve(rootDir, 'packages/widgets/components')

// https://vitejs.dev/config/
export default defineConfig({
  resolve: {
    alias: [
      {
        find: /^diit-widgets(\/(es|lib))?$/,
        replacement: path.resolve(rootDir, 'index.ts'),
      },
      {
        find: /^diit-widgets\/(es|lib)\/(.*)$/,
        replacement: `${packages}/$2`,
      },
    ],
  },
  plugins: [
    vue(),
    vueJsx(),
    Components({
      include: `${__dirname}/**`,
      resolvers: [
        AntDesignVueResolver(),
        PlusResolver()
      ],
      dts: false,
    }),
  ],
});
